package org.gp.demo.classload;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class CheckerClassVersion {
	static final Map<Integer, String> VERSION_MAP = new HashMap<Integer, String>();
	static {
		VERSION_MAP.put(Integer.valueOf(46), "1.2");
		VERSION_MAP.put(Integer.valueOf(47), "1.3");
		VERSION_MAP.put(Integer.valueOf(48), "1.4");
		VERSION_MAP.put(Integer.valueOf(49), "1.5");
		VERSION_MAP.put(Integer.valueOf(50), "1.6");
	}

	public static void main(String[] args) throws IOException {
		checkClassVersion(new FileInputStream("F:/CheckerClassVersion.class"));
	}

	public static void checkClassVersion(InputStream iStream)
			throws IOException {
		DataInputStream in = new DataInputStream(iStream);

		int magic = in.readInt();
		if (magic != 0xcafebabe) {
			System.out.println(" is not a valid class!");
		}
		int minor = in.readUnsignedShort();
		int major = in.readUnsignedShort();
		System.out.print(": " + major + "." + minor + " jdk:"
				+ VERSION_MAP.get(major));
		in.close();
	}
}
